<?php
/**
 * Created by PhpStorm.
 * User: PHP
 * Date: 2021/6/9
 * Time: 9:56
 */
namespace App\Services\config;
use App\Services\BaseServices;
use App\Dao\config\UploadDao;
use App\Exceptions\ApiException as HOException;
use Hlcreation\Basic\Helper;
use Illuminate\Support\Facades\DB;
class UploadServices extends BaseServices
{

    protected $dao;

    public function __construct(UploadDao $dao)
    {

        $this->dao = $dao;
    }

    //添加阿里云配置
    public function UploadAliSave($data){
        switch ($data['type']){
            case 1 :
                $data['desc'] = '阿里云文件上传配置';
                $data['config_tab_id'] = 32;;
                break;
            case 2 :
                $data['desc'] = '腾讯云文件上传配置';
                $data['config_tab_id'] = 34;
                break;
            case 3 :
                $data['desc'] = '七牛云文件上传配置';
                $data['config_tab_id'] = 33;
                break;
            /*default:
                $service_type = 0;*/
        }

        return $this->dao->Fileinsert($data);
    }


    public function  fileInfos($uid,$type){
        return $this->dao->fileInfos($uid,$type);
    }


    //阿里云配置信息显示  ---  作废
    public function UploadInfo($uid){
        $data= $this->dao->UploadInfo($uid);

        $aliyun_uploads = ['access_key'=>'','area'=>'','domain'=>'','secret_key'=>'','status'=>'','storage_title'=>'','type'=>1];
        $tengxun_uploads=['access_key'=>'','area'=>'','domain'=>'','secret_key'=>'','status'=>1,'storage_title'=>'','type'=>1];
        $qiniu_uplaods=['access_key'=>'','area'=>'','domain'=>'','secret_key'=>'','status'=>1,'storage_title'=>'','type'=>1];
        $orm_set=['floor_cr'=>'','login_bg'=>'','show_status'=>'1','site_logo'=>'','site_title'=>'','status'=>1,'type'=>6];
        $sign_sms=['sign'=>'','status'=>0];


        foreach($data as $k=>$v){
            switch ($v['config_tab_id']){
                case 32 :
                    $aliyun_uploads[$v['menu_name']] = $v['value'];
                    $aliyun_uploads['type']=1;

                    break;
                case 33 :
                    $qiniu_uplaods[$v['menu_name']] = $v['value'];
                    $qiniu_uplaods['type']=3;

                    break;
                case 34 :
                    $tengxun_uploads[$v['menu_name']] = $v['value'];
                    $tengxun_uploads['type']=2;


                    break;
                case 40 :
                    $orm_set[$v['menu_name']] = $v['value'];
                    $config=$this->GetStatus($uid,[40]);
                    $orm_set['status']=$config['status'];
                    break;
                case 41 :
                    $sign_sms[$v['menu_name']] = $v['value'];
                    $config=$this->GetStatus($uid,[40]);
                    $sign_sms['status']=$config['status'];
                    break;

            }



        }

        $upload_set['aliyun_uploads']=$aliyun_uploads;
        $upload_set['tengxun_uploads']=$tengxun_uploads;
        $upload_set['qiniu_uplaods']=$qiniu_uplaods;
        $config=$this->GetStatus($uid,[32,33,34]);
        if($config){
            $upload_set['status']=$config['status'];
        }else{
            $upload_set['status']=0;
        }



        return compact('upload_set','orm_set','sign_sms');

    }


    /**
     * 获取状态
     */
    public  function  GetStatus($uid,$config_tab_id){
        return $this->dao->GetStatus($uid,$config_tab_id);

    }







}
